﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using System.Windows.Input;
using SH.Data.View.ViewModel;
using SH.Data.View;

namespace SH.Client.WPF.View
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // установка соединения
            //Database.SetInitializer(new MigrateDatabaseToLatestVersion<ModelContainer, Configuration>());
            //context = new ModelContainer();
            //context.Database.Initialize(false);

            DataContext = new MainWindowViewModel();
            Exit = new DelegateCommand((x) => MenuItemClick1(this, null));
            //Application.Current.MainWindow.Title = GetTitle;

            Title = WindowTitle;
        }
        
        public string WindowTitle
        {
            get
            {
                var assembly = Assembly.GetEntryAssembly();

                object[] customAttributes;
                // получение версии
                customAttributes = assembly.GetCustomAttributes(typeof (AssemblyFileVersionAttribute), false);
                var productVersion = ((AssemblyFileVersionAttribute) customAttributes[0]).Version ?? string.Empty;
                // получение названия продукта
                customAttributes = assembly.GetCustomAttributes(typeof (AssemblyTitleAttribute), false);
                var productTitle = ((AssemblyTitleAttribute) customAttributes[0]).Title;

                return productTitle + " :: " + productVersion;
            }
        }

        public ICommand Exit { get; private set; }

        private void MenuItemClick1(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Ви впевненні?", "Вихід", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                Close();
        }
    }
}